/***************************************************************************\
 * The Mattise Kernel														*
 * Copyright 2007 Matthew Iselin											*
 * Licensed under the GPL													*
 *																			*
 * reloc.cc																	*
 *																			*
 * Relocation superclass, all relocations need to be done in terms of this	*
 * class																	*
 *																			*
\***************************************************************************/

// Includes
#include <system.h>
#include <stdio.h>
#include <reloc.h>
#include <memory.h>
#include <string.h>

// Class Definition

Relocation::Relocation()
{
}

Relocation::~Relocation()
{
	// close the file
	fclose( fp );
	kfree( fileName );
}

bool Relocation::LoadFile( const char* fn )
{	
	// copy the filename
	fileName = (char*) kmalloc( strlen( fn ) + 1 );
	memset( fileName, 0, strlen( fn ) + 1 );
	strcpy( fileName, fn );
	
	// open the file
	fp = fopen( fn, "rw" );
	
	// valid?
	if( fp.size == 0 )
		return false;
	
	// allocate enough space for the file
	fileData = (char*) kmalloc( fp.size );
	if( !fileData )
	{
		fclose( fp );
		return false;
	}
	memset( fileData, 0, fp.size ); // nullify the data, just in case
	
	// read in the data
	fread( fileData, 0, fp.size, fp );
	
	// ready to go
	return true;
}

uint_t Relocation::GetBase()
{
	// gets the address of the buffer
	return (uint_t) fileData;
}
